package com.javalearn.ssotest.gulimailtestssoclient.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.List;

@Controller
public class HelloController {
    /**
     * 无需登录就可访问
     * @return
     */
    @ResponseBody
    @GetMapping("/hello")
    public String hello(){
        return "hello";
    }

    @GetMapping("/employees")
    public String employees(Model model, HttpSession session){
        Object loginUser = session.getAttribute("loginUser");
        if (loginUser==null){
           //没登录，跳转到登录服务器进行登录
            return "redirect:";
        }else {
            List<String> emps = new ArrayList<>();
            emps.add("zhangsan");
            emps.add("lisi");
            model.addAttribute("emps",emps);
            return "list";
        }
    }
}
